home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’96 / Venus / EventHandlers.h < prev    next >
Text File  |  1996-06-22  |  2KB  |  58 lines

  1. /*
  2.  ***********************************************************************
  3.  *
  4.  *
  5.  *                        Event Handler Classes
  6.  *        
  7.  *
  8.  ***********************************************************************
  9.  */
  10.  
  11. #if 0
  12.                                 // Registering handler for the null events
  13.                                 // It's an abstract class. You need to subclass
  14.                                 // it and define your own null event handler
  15. class NullEventHandler
  16. {
  17.   friend class EventHandler;
  18.   const long event_timeout;                    // For WaitNextEvent, set pacing for null events
  19.   static NullEventHandler * first_handler;
  20.     // NullEventHandler * prev_handler;    // We don't chain null event handlers at
  21.                                         // present. But this is in case we will
  22.                                         // in the future
  23.  
  24.                                     // Takes the time (in ticks) when the null
  25.                                     // event was received. Return FALSE to
  26.                                     // quit
  27.   virtual Boolean handle_null_event(const long event_time) = 0;
  28.  
  29. public:
  30.                                     // No chaining at the moment
  31.   NullEventHandler(void)  : first_handler(this) {}
  32.   ~NullEventHandler(void) : first_handler(nil)   {}
  33. };
  34.  
  35. #endif
  36.  
  37.                                     // Obviously this event handler assumes that an
  38.                                     // application has the _only_ one window
  39.                                     // to handle events for.
  40.                                     // It's a very primitive case, but that'll be
  41.                                     // enough
  42.                                     // It's kind of silly to define a class for the
  43.                                     // sake of only one method, loop(), which may well
  44.                                     // be just a regular function. It'll pay off later
  45.                                     // when we're going to have more than one window
  46.                                     // to take care of
  47. class ScreenWindow;
  48. class EventHandler
  49. {
  50.   EventRecord the_event;
  51.   const long event_timeout;                // waiting for the next event
  52.   ScreenWindow& serviced_window;
  53. public:
  54.   EventHandler(ScreenWindow& window_to_serve, const long _event_timeout=5)
  55.     : serviced_window(window_to_serve), event_timeout(_event_timeout) {}
  56.   void loop(void);
  57. };
  58.